function lengthOfLongestSubstring(s: string): number {
    if(s.length === 1){
        return 1
    }
  // 双指针
  let left = 0;
  let right = 0;
  let n = s.length;
  const map1 = new Map<string, number>();
  let maxLength = 0;
  for (right; right < n; right++) {
    let cur = s[right];
    if (map1.has(cur)) {
      let mapIdx = map1.get(cur)!;
      if (mapIdx >= left) {
        left = mapIdx + 1;
      }
    }

    map1.set(cur, right);
    maxLength = Math.max(right - left + 1, maxLength);
  }
  return maxLength;
}